package com.etc.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.etc.dao.FxMusicianMapper;
import com.etc.entity.FxMusician;
import com.etc.service.FxMusicianService;
import com.github.pagehelper.PageHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FxMusicianServiceImpl implements FxMusicianService {
    @Autowired
    FxMusicianMapper mapper;

    Logger logger = (Logger) LogManager.getLogger(getClass());

    //查询

    /**
     * 用于登入
     */
    @Override
    public FxMusician select_MusicianLogin(String name, String password) {
        password = SecureUtil.md5(password);
        FxMusician fxMusician = mapper.select_MusicianLogin(name, password);

        return fxMusician;
    }

    /**
     * 查询所有歌手信息
     * @return admin
     */
    public List<FxMusician> selectMusicianAll(){
        List<FxMusician> list = mapper.selectMusicianAll();

        return list;
    }

    /**
     * 根据 id 查询管理员
     */
    public FxMusician selectMusicianByPrimaryKey(Integer id){
        FxMusician fxMusician = mapper.selectMusicianByPrimaryKey(id);

        return fxMusician;
    }

    /**
     * 根据 keywords 分页模糊查询管理员
     */
    public List<FxMusician> selectMusicianByPage(int pageNo, int pageSize, String keywords){
        PageHelper.startPage(pageNo,pageSize);
        List<FxMusician> list = mapper.selectByPage("%"+ keywords +"%");

        return list;
    };

    @Override
    public List<FxMusician> selectMusicianByPage(int pageNo, int pageSize, String keywords, String genres, String type) {
        PageHelper.startPage(pageNo,pageSize);
        List<FxMusician> list = mapper.selectMusicianByPage("%"+ keywords +"%", "%"+ genres +"%", "%"+ type +"%");

        return list;
    }

    //添加

    /**
     * 添加管理员
     * 1 - admin - admin - 21232f297a57a5a743894a0e4a801fc3
     * 2 - root - 123456 - e10adc3949ba59abbe56e057f20f883e
     */
    public boolean insertMusician(FxMusician fxMusician){
        String md5Pwd = SecureUtil.md5(fxMusician.getMusicianpwd());
        fxMusician.setMusicianpwd(md5Pwd);
        int result = mapper.insertMusician(fxMusician);
        return result > 0;
    }

    /**
     *
     */
    public boolean insertMusicianSelective(FxMusician record){
        String md5Pwd = SecureUtil.md5(record.getMusicianpwd());
        record.setMusicianpwd(md5Pwd);
        int result = mapper.insertMusician(record);
        return result > 0;
    };

    //修改

    /**
     * 选择部分信息修改
     */
    public boolean updateMusicianByPrimaryKeySelective(FxMusician fxMusician){
        String md5Pwd = SecureUtil.md5(fxMusician.getMusicianpwd());
        fxMusician.setMusicianpwd(md5Pwd);
        int result = mapper.updateMusicianByPrimaryKeySelective(fxMusician);

        return result > 0;
    }

    /**
     * 全部信息修改
     */
    public boolean updateMusicianByPrimaryKey(FxMusician fxMusician){
        String md5Pwd = SecureUtil.md5(fxMusician.getMusicianpwd());
        fxMusician.setMusicianpwd(md5Pwd);
        int result = mapper.updateMusicianByPrimaryKeySelective(fxMusician);

        return result > 0;
    }

    //删除

    /**
     * 根据 id 删除管理员
     */
    public boolean deleteMusicianByPrimaryKey(Integer id){
        int result = mapper.deleteMusicianByPrimaryKey(id);

        return result > 0;
    }

}
